package com.xgg.taiwuinfo.filter.fc;

import android.content.Context;
import android.util.Log;

import com.xgg.taiwuinfo.R;
import com.xgg.taiwuinfo.filter.FC_EqualSelect;
import com.xgg.taiwuinfo.filter.FilterComponent;
import com.xgg.taiwuinfo.gongfa.base.Gongfa;
import com.xgg.taiwuinfo.utils.Element;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class FCElementEqualSelect extends FC_EqualSelect {

    Context mctx;

    public FCElementEqualSelect(JSONObject obj , Context ctx)
    {
        mTypeId = FilterComponent.FT_ElEMENT_EQUAL_SELECT;
        mctx = ctx;
        if (obj != null) {
            try {
                ReadValue = obj.getInt("v");
                ReadCompare = obj.getInt("c");
            } catch (Exception e) {
                Log.d("LoadJson", e.getLocalizedMessage());
                ReadValue = Element.ELEMENT_NONE;
                ReadCompare = FC_EQUAL;
            }
        }
        else {
            ReadValue = Element.ELEMENT_NONE;
            ReadCompare = FC_EQUAL;
        }
        TempValue = ReadValue;
        TempCompare = ReadCompare;

        FieldStr = "功法五行";
        if (mValueMap == null) {
            mValueMap = new ArrayList<>();
            Map<String, String> map;

            map = new HashMap<>();
            map.put("f", ctx.getString(R.string.element_none));
            map.put("v", Element.ELEMENT_NONE + "");
            mValueMap.add(map);
            map = new HashMap<>();
            map.put("f", ctx.getString(R.string.element_metal));
            map.put("v", Element.ELEMENT_METAL + "");
            mValueMap.add(map);
            map = new HashMap<>();
            map.put("f", ctx.getString(R.string.element_wood));
            map.put("v", Element.ELEMENT_WOOD + "");
            mValueMap.add(map);
            map = new HashMap<>();
            map.put("f", ctx.getString(R.string.element_water));
            map.put("v", Element.ELEMENT_WATER + "");
            mValueMap.add(map);
            map = new HashMap<>();
            map.put("f", ctx.getString(R.string.element_fire));
            map.put("v", Element.ELEMENT_FIRE + "");
            mValueMap.add(map);
            map = new HashMap<>();
            map.put("f", ctx.getString(R.string.element_earth));
            map.put("v", Element.ELEMENT_EARTH + "");
            mValueMap.add(map);
        }
    }

    @Override
    public String FilterGongfa(Gongfa gongfa){
        if (gongfa.mElement == ReadValue ^ !(ReadCompare == FC_EQUAL))
        {
            return gongfa.getElementString(mctx);
        }
        else
            return null;
    }

    @Override
    public List<Map<String, String>> getFieldString(Context ctx){
        List<Map<String, String>> mCompMap = new ArrayList<>();
        Map<String, String> map;

        map = new HashMap<>();
        map.put("f", FieldStr);
        map.put("v",   "0");
        mCompMap.add(map);

        return mCompMap;
    }

    @Override
    public List<Map<String, String>> getValueMap(Context ctx)
    {

        return mValueMap;
    }


}
